// Copyright (c) 2020 Presto Labs Pte. Ltd.
// Author: donggu

#pragma once

// std
#include <map>
#include <memory>
#include <regex>
#include <string>
#include <vector>

#include <fmt/format.h>
#include <rapidjson/schema.h>
#include <simdjson.h>

// internal
#include "coin2/base/log.h"
#include "coin2/exchange/base/feed/processor.h"
#include "coin2/exchange/base/market/enums.h"

namespace coin2::exchange::okex_common::feed_v3 {

namespace impl {

using namespace std::string_literals;
using namespace coin2::exchange::base::symbology;
using coin2::exchange::base::market::ExchangeType;
using coin2::exchange::base::market::MarketType;

class OkexCommonFeedProcessor : public base::feed::FeedParsingProcessor {
 public:
  OkexCommonFeedProcessor(const std::string& system_name,
                          const coin2::exchange::di::ConstantInjection& ci,
                          const feed::RawParserConfig& config,
                          const MarketExchangeApi& mea)
      : FeedParsingProcessor(
            system_name,
            mea,
            ci,
            config,
            fmt::format("cc/coin2/exchange/okex{}/feed_v3/schema.json",
                        (mea.market == MarketType::Spot ? "" : "_futures"))),
        publish_bbo_book_only_(config.publish_bbo_book_only()) {
  }

  void OnTopicRecord(const base::executor::TopicRecordPacket& packet) override;
  bool CheckChannelFilter(const std::string& ch) override;
 private:
  simdjson::dom::parser parser_;
  const bool publish_bbo_book_only_;
  std::optional<bool> long_topic_;  // kline only work for 1 worker
  std::optional<int> picked_worker;  // kline only work for 1 worker
};

}  // namespace impl
using impl::OkexCommonFeedProcessor;
}  // namespace coin2::exchange::okex_common::feed_v3
